<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card class="box-card">
      <el-row :gutter="20" class="search-box">
        <el-col :span="7">
          <!-- 后端没有完成查询订单的操作 -->
          <el-input placeholder="请输入内容" v-model="paramObj.query" class="input-with-select" clearable
            @clear="getOrderList">
            <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 订单列表 -->
      <el-table :data="orderList" style="width: 100%">
        <!-- 索引列 -->
        <el-table-column type="index" label="#">
        </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格">
        </el-table-column>
        <el-table-column label="是否付款">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === 1">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货">
        </el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column>
          <template>
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="editDialogVisible = true"></el-button>
            <el-button type="success" icon="el-icon-location" size="mini" @click="getLoginInfo"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页条 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="paramObj.pagenum" :page-sizes="[5, 10, 30]" :page-size="paramObj.pagesize"
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
      <!-- 修改地址对话框 -->
      <el-dialog title="修改地址" :visible.sync="editDialogVisible" width="30%" @close="handleClose">
        <el-form :model="editForm" :rules="editFormRules" ref="editFormRef" label-width="100px" class="demo-ruleForm">
          <el-form-item label="省市区/县" prop="address">
            <!-- 选择地址的级联选择器 -->
            <el-cascader v-model="editForm.address1" :options="cityData" :props="cascaderProps">
            </el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="detail">
            <el-input v-model="editForm.address2"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="editDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="editDialogVisible = false">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 查看物流信息对话框 -->
      <el-dialog title="物流信息" :visible.sync="InfoDialogVisible" width="30%">
        <!-- 时间线 -->
        <el-timeline>
          <el-timeline-item v-for="(item, i) in loginInfo" :key="i" :timestamp="item.ftime">
            {{ item.context }}
          </el-timeline-item>
        </el-timeline>
      </el-dialog>

    </el-card>
  </div>
</template>

<script>
import cityData from './citydata.js'
export default {
  data() {
    return {
      paramObj: {
        query: '',
        pagenum: 1,
        pagesize: 5,
      },
      total: 0,
      // 订单列表数据
      orderList: [],
      // 物流信息数据
      loginInfo: [],
      // 编辑对话框
      editDialogVisible: false,
      // 物流信息对话框
      InfoDialogVisible: false,
      editForm: {
        address1: [],
        address2: ''
      },
      // 编辑表单规则
      editFormRules: {
        address1: [{ required: true, message: '请输入省市区/县', trigger: 'blur' }],
        address2: [{ required: true, message: '请输入详细地址', trigger: 'blur' }]
      },
      // cityData:cityData,
      cityData,
      // 级联选择器的配置对象
      cascaderProps: {
        expandTrigger: 'hover',
        label: 'label',
        value: 'value',
        children: 'children'

      },
    }
  },
  methods: {
    // 获取订单数据列表
    async getOrderList() {
      const { data: res } = await this.$http.get('orders', { params: this.paramObj });
      // console.log(res)
      if (res.meta.status !== 200) return this.$msg.error("获取订单列表数据失败");
      this.orderList = res.data.goods;
      this.total = res.data.total;
    },
    // 监听页面大小变化
    handleSizeChange(newSize) {
      this.paramObj.pagesize = newSize;
      this.getOrderList();
    },
    // 监听页码改变
    handleCurrentChange(newPage) {
      this.paramObj.pagenum = newPage;
      this.getOrderList();
    },
    // 监听对话框的关闭
    handleClose() {
      this.$refs.editFormRef.resetFields();
      // console.log(this.editForm.address1)
    },
    // 获取物流信息数据
    async getLoginInfo() {
      this.InfoDialogVisible = true;
      const { data: res } = await this.$http.get('/kuaidi/1106975712662');
      // console.log(res)
      if (res.meta.status !== 200) return this.$msg.error("获取物流信息失败");
      this.loginInfo = res.data;
    },

  },
  created() {
    this.getOrderList();
  }

}
</script>

<style lang="less" scoped>
</style>